package tools.packet;

import handling.opcode.SendPacketOpcode;

import java.awt.*;
import java.util.Iterator;
import java.util.List;

import server.life.FairyDust;
import tools.Randomizer;
import tools.data.output.MaplePacketLittleEndianWriter;


public class LucidPacket {
    public static byte[] createDragon(int phase, int posX, int posY, int createPosX, int createPosY, boolean isLeft) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
        mplew.writeShort(SendPacketOpcode.LUCID_CREATE_DRAGON.getValue());
        mplew.writeInt(phase);
        mplew.writeInt(posX);
        mplew.writeInt(posY);
        mplew.writeInt(createPosX);
        mplew.writeInt(createPosY);
        mplew.writeBool(isLeft);
        return mplew.getPacket();
    }


    public static byte[] doFlowerTrapSkill(int level, int pattern, int x, int y, boolean flip) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
        mplew.writeShort(SendPacketOpcode.LUCID_USE_SKILL.getValue());
        mplew.writeInt(238);
        mplew.writeInt(level);
        mplew.writeInt(pattern);
        mplew.writeInt(x);
        mplew.writeInt(y);
        mplew.writeBool(flip);
        return mplew.getPacket();
    }


    public static byte[] LaserRainSkill(int startDelay, List<Integer> intervals) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
        mplew.writeShort(SendPacketOpcode.LUCID_USE_SKILL.getValue());
        mplew.writeInt(238);
        mplew.writeInt(5);
        mplew.writeInt(startDelay);
        mplew.writeInt(intervals.size());
        for (Iterator<Integer> iterator = intervals.iterator(); iterator.hasNext(); ) {
            int interval = ((Integer) iterator.next()).intValue();
            mplew.writeInt(interval);
        }

        return mplew.getPacket();
    }


    public static byte[] doFairyDustSkill(int level, List<FairyDust> fairyDust) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
        mplew.writeShort(SendPacketOpcode.LUCID_USE_SKILL.getValue());
        mplew.writeInt(238);
        mplew.writeInt(level);
        mplew.writeInt(fairyDust.size());
        for (FairyDust fd : fairyDust) {
            mplew.writeInt(fd.getScale());
            mplew.writeInt(fd.getCreateDelay());
            mplew.writeInt(fd.getMoveSpeed());
            mplew.writeInt(fd.getAngle());
        }
        return mplew.getPacket();
    }


    public static byte[] ShowSteps(boolean enable, List<String> tags) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
        mplew.writeShort(SendPacketOpcode.LUCID_SHOW_STEPS.getValue());
        mplew.writeBool(enable);
        mplew.writeInt(tags.size());
        for (String name : tags) {
            mplew.writeMapleAsciiString(name);
        }
        return mplew.getPacket();
    }


    public static byte[] changeStatueState(boolean placement, int gauge, boolean enable) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
        mplew.writeShort(SendPacketOpcode.LUCID_STATUE_STATE_CHANGE.getValue());
        mplew.writeInt(placement ? 1 : 0);
        if (placement) {
            mplew.writeBool(enable);
        } else {
            mplew.writeInt(gauge);
            mplew.writeBool(enable);
        }
        return mplew.getPacket();
    }


    public static byte[] setFlyingMode(boolean value) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
        mplew.writeShort(SendPacketOpcode.LUCID_FLYING_MODE.getValue());
        mplew.writeBool(value);
        return mplew.getPacket();
    }


    public static byte[] UseScreenShoot(int type) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
        mplew.writeShort(SendPacketOpcode.LUCID_SCREEN_ATK.getValue());
        mplew.writeInt(type);
        return mplew.getPacket();
    }
    public static byte[] doRushSkill() {
        MaplePacketLittleEndianWriter var0 = new MaplePacketLittleEndianWriter();
        var0.writeShort(SendPacketOpcode.LUCID_USE_SKILL.getValue());
        var0.writeInt(238);
        var0.writeInt(8);
        var0.writeInt(0);
        return var0.getPacket();
    }

    public static byte[] doBidirectionShoot(int x, int y, int xx, int yy) {
        MaplePacketLittleEndianWriter var4 = new MaplePacketLittleEndianWriter();
        var4.writeShort(SendPacketOpcode.LUCID_SCREEN_ATK.getValue());
        var4.writeInt(3);
        var4.writeInt(x);
        var4.writeInt(y);
        var4.writeInt(xx);
        var4.writeInt(yy);
        return var4.getPacket();
    }
    public static byte[] doForcedTeleportSkill(int a) {
        MaplePacketLittleEndianWriter var1 = new MaplePacketLittleEndianWriter();
        var1.writeShort(SendPacketOpcode.LUCID_USE_SKILL.getValue());
        var1.writeInt(238);
        var1.writeInt(6);
        var1.writeInt(a);
        return var1.getPacket();
    }

    public static byte[] doSpiralShoot(int a, int b, int c, int d, int e, int f, int g, int h) {
        MaplePacketLittleEndianWriter var8 = new MaplePacketLittleEndianWriter();
        var8.writeShort(SendPacketOpcode.LUCID_SCREEN_ATK.getValue());
        var8.writeInt(4);
        var8.writeInt(a);
        var8.writeInt(b);
        var8.writeInt(c);
        var8.writeInt(d);
        var8.writeInt(e);
        var8.writeInt(f);
        var8.writeInt(g);
        var8.writeInt(h);
        return var8.getPacket();
    }

    public static byte[] showLucidSpecialAttack(int n2) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

        mplew.writeShort(SendPacketOpcode.LUCID_SCREEN_ATK.getValue());
        mplew.writeInt(n2);
        switch (n2) {
            case 0: {
                mplew.writeInt(0);
                mplew.writeInt(0);
                break;
            }
            case 1: {
                break;
            }
            case 2: {
                break;
            }
            case 5: {
                break;
            }
            case 3: {
                mplew.writeInt(Randomizer.rand(30, 45));
                mplew.writeInt(Randomizer.rand(45, 55));
                mplew.writeInt(Randomizer.rand(600, 700));
                mplew.writeInt(Randomizer.rand(10, 30));
                break;
            }
            case 4: {
                mplew.writeInt(0);
                mplew.writeInt(0);
                mplew.writeInt(0);
                mplew.writeInt(0);
                mplew.writeInt(0);
                mplew.writeInt(0);
                mplew.writeInt(0);
                mplew.writeInt(0);
                break;
            }
        }

        return mplew.getPacket();
    }
    public static byte[] showLucidDragonAttack(int n2, boolean bl2) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

        mplew.writeShort(SendPacketOpcode.LUCID_CREATE_DRAGON.getValue());
        mplew.writeInt(n2);
        mplew.writeInt(1);
        mplew.writeInt(1);
        mplew.writeInt(0);
        mplew.writeInt(0);
        mplew.writeBool(bl2);

        return mplew.getPacket();
    }

}